﻿<ResourceDictionary 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:Controls="clr-namespace:Magellan.Controls" xmlns:ComponentModel="clr-namespace:System.ComponentModel;assembly=PresentationFramework">

    <Style TargetType="Controls:Layout">
        <Setter Property="Focusable" Value="False" />
    </Style>
    
    <Style TargetType="Controls:Zone">
        <Setter Property="Focusable" Value="False" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="Controls:Zone">
                    <ContentPresenter />
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="Controls:ZonePlaceHolder">
        <Setter Property="Focusable" Value="False" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="Controls:ZonePlaceHolder">
                    <ContentPresenter />
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>


    <Style TargetType="{x:Type  Controls:Field}">
        <Setter Property="Focusable" Value="False" />
        <Setter Property="Header" Value="{Binding RelativeSource={RelativeSource Self}, Path=InferredHeader}" />
        <Setter Property="Description" Value="{Binding RelativeSource={RelativeSource Self}, Path=InferredDescription}" />
        <Setter Property="IsRequired" Value="{Binding RelativeSource={RelativeSource Self}, Path=InferredIsRequired}" />
        <Setter Property="Margin" Value="0,3,0,3" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Controls:Field}">
                    <Border 
                        x:Name="_border" 
                        Background="Transparent" 
                        BorderThickness="0" 
                        BorderBrush="Transparent"
                        >
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition MinWidth="110" Width="Auto" SharedSizeGroup="FieldHeaderGridGroup" />
                                <ColumnDefinition Width="Auto" MinWidth="400" MaxWidth="500" />
                                <ColumnDefinition Width="*" />
                            </Grid.ColumnDefinitions>

                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto" />
                            </Grid.RowDefinitions>

                            <Border Grid.Column="0" Grid.Row="0" MaxWidth="150">
                                <StackPanel Margin="0,0,0,0" HorizontalAlignment="Left" VerticalAlignment="Top">
                                    <Label 
                                        x:Name="PART_FieldNameLabel"
                                        Margin="0" Padding="0" 
                                        Target="{Binding Path=Content, RelativeSource={RelativeSource TemplatedParent}}"
                                        >
                                        <ContentPresenter Content="{TemplateBinding Property=Header}" />
                                    </Label>
                                </StackPanel>
                            </Border>

                            <Border Grid.Column="1" Grid.Row="0" VerticalAlignment="Top">
                                <StackPanel HorizontalAlignment="Stretch" VerticalAlignment="Top">
                                    <ContentPresenter HorizontalAlignment="Left"/>

                                    <Border x:Name="PART_DesignerHint" Background="LightYellow" Visibility="Collapsed">
                                        <TextBlock Text="This field will be evaluated at runtime" />
                                    </Border>
                                    
                                    <TextBlock 
                                        x:Name="PART_DescriptionTextBlock"
                                        TextWrapping="Wrap"
                                        HorizontalAlignment="Left"
                                        MaxWidth="400"
                                        Margin="0,5,0,3"
                                        Foreground="#999999"
                                        Text="{TemplateBinding Property=Description}" 
                                        />
                                </StackPanel>
                            </Border>

                        </Grid>
                    </Border>

                    <ControlTemplate.Triggers>
                        <Trigger Property="Description" Value="">
                            <Setter TargetName="PART_DescriptionTextBlock" Property="Visibility" Value="Collapsed" />
                        </Trigger>
                        <Trigger Property="Description" Value="{x:Null}">
                            <Setter TargetName="PART_DescriptionTextBlock" Property="Visibility" Value="Collapsed" />
                        </Trigger>
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="ComponentModel:DesignerProperties.IsInDesignMode" Value="True" />
                                <Condition Property="Content" Value="{x:Null}" />
                            </MultiTrigger.Conditions>
                            <Setter TargetName="PART_DesignerHint" Property="Visibility" Value="Visible" />
                        </MultiTrigger>
                        <Trigger Property="IsRequired" Value="True">
                            <Setter TargetName="PART_FieldNameLabel" Property="FontWeight" Value="Bold" />
                        </Trigger>
                    </ControlTemplate.Triggers>

                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="{x:Type Controls:Form}">
        <Setter Property="Focusable" Value="False" />
        <Setter Property="Grid.IsSharedSizeScope" Value="True" />
        <Setter Property="ItemsPanel">
            <Setter.Value>
                <ItemsPanelTemplate>
                    <StackPanel />
                </ItemsPanelTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type  Controls:Form}">
                    <Border SnapsToDevicePixels="True">
                        <Border SnapsToDevicePixels="True">
                            <DockPanel>
                                <ItemsPresenter />
                            </DockPanel>
                        </Border>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>


</ResourceDictionary>